use crate::enum_test::Options;
use trait_impl::trait_impl_test;
use array::arr;

mod array;
mod enum_test;
mod if_else;
mod if_let;
mod match_test;
mod number_test;
mod string_test;
mod struct_test;
mod test_folder;
mod trait_add_test;
mod trait_impl;
mod tuple_test;
mod vector_test;

fn main() {
    string_test::string_test();
    number_test::number_test();

    // 闭包
    {
        let a: char = 'a';
        println!("{}", a);
    }

    if_else::print_if_else();
    if_let::if_let(0, true);
    vector_test::vector();
    test_folder::test_folder();
    test_folder::test_folders::test();
    match_test::match_test();
    // 报错 expected `i32`, found `()`
    // fn while_true(x: i32) -> i32
    // {
    //     while true {
    //         return x + 1;
    //     }
    // }
    // let y: i32 = while_true(5);
    let mut x: i32 = 0;
    loop {
        x = x + 1;
        if x > 5 {
            break;
        }
        println!("{}", x);
    }
    enum_test::enum_test(enum_test::Week::Thu, enum_test::Sex::Queer(3));
    tuple_test::tuple();
    println!("{}", '/' as i16);
    assert_eq!('/' as u8, 47);
    let struct_test: struct_test::Citizen = struct_test::Citizen {
        name: "liutao",
        gender: 23,
        age: 12,
    };
    let my_struct: struct_test::Student = struct_test::Student {
        Id: 200502131510,
        Name: String::from("Extra·Fang"),
        Age: 18,
    };
    println!(
        "{}\n{}\n{}",
        struct_test.name, struct_test.gender, struct_test.age
    );
    println!(
        "{}\n{}\n{}\n{:#?}",
        my_struct.Id, my_struct.Name, my_struct.Age, my_struct
    );
    impl struct_test::Student {
        fn new(id: u64, name: String, age: u16) -> Self {
            return struct_test::Student {
                Id: id,
                Name: name,
                Age: age,
            };
        }
    }
    let name: String = String::from("Extra");
    let instance: struct_test::Student = struct_test::Student::new(43154325531, name, 18);
    println!("{}", instance.Id);
    let x: i8 = 63;
    println!("{:p}\n{:x}", &x, &x); // p是指打印地址，x是打印16进制数
    let opt = Some(20);
    match opt {
        Some(n) => println!("{}", n),
        None => println!("Plz input sth. useful!")
    }
    let val: Options = enum_test::Options::Some(62);
    println!("{:?}", enum_test::Options::Some(12));
    match val {
        Options::Some(n) => println!("{}", n),
        Options::None => ()
    }
    // 新建一个Option，并设置Some值为23
    let val: Option<u32> = Some(23);
    // 将val从Some类型中取出
    let a: u32 = val.unwrap();
    println!("{}", a);
    let mut b = String::from("hello");
    b += &" world".to_string();
    println!("{}", b);
    let mut arr = arr::Array::new();
    println!("{:?}", arr);
    arr.change_one(4, 45);
    println!("{:?}", arr);
    let Extra = trait_impl_test::Person {
        id: 20050213,
        name: String::from("Extra"),
        age: 18,
        job: trait_impl_test::job::worker
    };
    println!("{:?}", Extra);
    let d = trait_add_test::trait_add::Point { x: 23, y: 200520213 };
    let e = trait_add_test::trait_add::Point { x: 54, y: 3432443 };
    println!("{:?}", d + e);
}
